/* -----------------------------------------------------------------------------
 * PROJECT    : lwf
 * FILE       : LookupService.java
 *
 * HISTORY:
 * Date          Author                        Description
 * ----------------------------------------------------------------------------- 
 * Mar 1, 2011  mycodetalks			       Created
 */
package net.lwf.service;

import java.util.ArrayList;
import java.util.List;

import net.lwf.factory.lookup.LookupFactory;
import net.lwf.hibernate.entity.lookup.Lookup;
import net.lwf.lookup.fake.service.MockLookupService;

/**
 * Class description goes here
 */
public class LookupService {
	
	public String getValue(String group, String key) {
		if(LwfService.isMock()) {
			return this.getMockValue(group, key);
		}
		return LookupFactory.getInstance().getValue(group, key);
	}
	
	public List<Lookup> getData(String group) {
		if(LwfService.isMock()) {
			return this.getMockData(group);
		}
		return LookupFactory.getInstance().getData(group);
	}
	
	//---------------------------------------------------------------------------------------------
	// Mock Data retrieval methods
	//---------------------------------------------------------------------------------------------
	
	private String getMockValue(String group, String key) {
		return this.getMockService().getLookupValue(group, key);
	}
	
	private List<Lookup> getMockData(String group) {
		List<Lookup> lookups = new ArrayList<Lookup>();

		List<net.lwf.lookup.fake.jaxb.Lookup> lookupdata = this.getMockService().getData(group);
		
		for(net.lwf.lookup.fake.jaxb.Lookup mocklookup: lookupdata) {
			Lookup lookup = new Lookup();
			lookup.setId(Long.parseLong(mocklookup.getId()));
			lookup.setGroup(mocklookup.getGroup());
			lookup.setKey(mocklookup.getKey());
			lookup.setValue(mocklookup.getValue());
			lookup.setStatus(mocklookup.getStatus());
			lookups.add(lookup);
		}
		return lookups;
	}
	
	private MockLookupService getMockService() {
		return new MockLookupService();
	}

}



